d774199cdf711c078f306a15a2b112f0356efb81,platform/lang-impl/src/com/intellij/codeEditor/printing/TextPainter.java,TextPainter,print,#Graphics#PageFormat#number#,152
Before Change
@Override
public int print(final Graphics g, final PageFormat pageFormat, final int pageIndex) throws PrinterException {
if (myOffset >= mySegmentEnd || myProgress.isCanceled()) {
return Printable.NO_SUCH_PAGE;
}
isPrintingPass = !isPrintingPass;
if (!isPrintingPass) {
return Printable.PAGE_EXISTS;
}
myProgress.setText(CodeEditorBundle.message("print.file.page.progress", myFileName, (pageIndex + 1)));
ApplicationManager.getApplication().runReadAction(new Runnable() {
@Override
public void run() {
myPageIndex = pageIndex;
Graphics2D g2D = (Graphics2D) g;
Rectangle2D.Double clip = new Rectangle2D.Double(pageFormat.getImageableX(), pageFormat.getImageableY(),
pageFormat.getImageableWidth(),
pageFormat.getImageableHeight());
double headerHeight = drawHeader(g2D, clip);
clip.y += headerHeight;
clip.height -= headerHeight;
double footerHeight = drawFooter(g2D, clip);
clip.height -= footerHeight;
Rectangle2D.Double border = (Rectangle2D.Double) clip.clone();
clip.x += getCharWidth(g2D) / 2;
clip.width -= getCharWidth(g2D);
if (myPrintSettings.PRINT_LINE_NUMBERS) {
double numbersStripWidth = calcNumbersStripWidth(g2D, clip) + getCharWidth(g2D) / 2;
clip.x += numbersStripWidth;
clip.width -= numbersStripWidth;
}
clip.x += getCharWidth(g2D) / 2;
clip.width -= getCharWidth(g2D);
drawText(g2D, clip);
drawBorder(g2D, border);
}
});
return Printable.PAGE_EXISTS;
}
After Change
@Override
public int print(final Graphics g, final PageFormat pageFormat, final int pageIndex) throws PrinterException {
return ApplicationManager.getApplication().runReadAction(new Computable<Integer>() {
@Override
public Integer compute() {
if (myProgress.isCanceled() || myRangeToPrint == null || !myRangeToPrint.isValid()) {
return NO_SUCH_PAGE;
}
int startOffset = myRangeToPrint.getStartOffset();
myOffset = startOffset;
mySegmentEnd = myRangeToPrint.getEndOffset();
myLineNumber = myDocument.getLineNumber(myOffset) + 1;
if (myOffset >= mySegmentEnd) {
return NO_SUCH_PAGE;
}
isPrintingPass = !isPrintingPass;
if (!isPrintingPass) {
return PAGE_EXISTS;
}
myProgress.setText(CodeEditorBundle.message("print.file.page.progress", myFileName, (pageIndex + 1)));
myPageIndex = pageIndex;
Graphics2D g2D = (Graphics2D) g;
Rectangle2D.Double clip = new Rectangle2D.Double(pageFormat.getImageableX(), pageFormat.getImageableY(),
pageFormat.getImageableWidth(),
pageFormat.getImageableHeight());
draw(g2D, clip);
myRangeToPrint.dispose();
// stop printing if there was no progress (to avoid an infinite loop) or if the whole range was processed
myRangeToPrint = myOffset > startOffset && myOffset < mySegmentEnd ? myDocument.createRangeMarker(myOffset, mySegmentEnd) : null;
return PAGE_EXISTS;
}
});
}
private void draw(Graphics2D g2D, Rectangle2D.Double clip) {